package cn.csc.module.order.dal.mysql.addr;

import cn.csc.framework.common.pojo.PageResult;
import cn.csc.framework.mybatis.core.mapper.BaseMapperX;
import cn.csc.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.csc.module.order.controller.admin.addr.vo.OrderAddrExportReqVO;
import cn.csc.module.order.controller.admin.addr.vo.OrderAddrPageReqVO;
import cn.csc.module.order.dal.dataobject.addr.OrderAddrDO;
import org.apache.ibatis.annotations.Mapper;

import java.math.BigInteger;
import java.util.List;

/**
 * 用户订单配送地址 Mapper
 *
 * @author liuchuang
 */
@Mapper
public interface OrderAddrMapper extends BaseMapperX<OrderAddrDO> {

    default PageResult<OrderAddrDO> selectPage(OrderAddrPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<OrderAddrDO>()
                .eqIfPresent(OrderAddrDO::getOrderId, reqVO.getOrderId())
                .eqIfPresent(OrderAddrDO::getOrderItemId, reqVO.getOrderItemId())
                .eqIfPresent(OrderAddrDO::getUserId, reqVO.getUserId())
                .eqIfPresent(OrderAddrDO::getConsignee, reqVO.getConsignee())
                .eqIfPresent(OrderAddrDO::getProvinceId, reqVO.getProvinceId())
                .eqIfPresent(OrderAddrDO::getProvince, reqVO.getProvince())
                .eqIfPresent(OrderAddrDO::getCityId, reqVO.getCityId())
                .eqIfPresent(OrderAddrDO::getCity, reqVO.getCity())
                .eqIfPresent(OrderAddrDO::getAreaId, reqVO.getAreaId())
                .eqIfPresent(OrderAddrDO::getArea, reqVO.getArea())
                .eqIfPresent(OrderAddrDO::getAddrDetail, reqVO.getAddrDetail())
                .eqIfPresent(OrderAddrDO::getPostCode, reqVO.getPostCode())
                .eqIfPresent(OrderAddrDO::getMobile, reqVO.getMobile())
                .eqIfPresent(OrderAddrDO::getLng, reqVO.getLng())
                .eqIfPresent(OrderAddrDO::getLat, reqVO.getLat())
                .betweenIfPresent(OrderAddrDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(OrderAddrDO::getId));
    }

    default List<OrderAddrDO> selectList(OrderAddrExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<OrderAddrDO>()
                .eqIfPresent(OrderAddrDO::getOrderId, reqVO.getOrderId())
                .eqIfPresent(OrderAddrDO::getOrderItemId, reqVO.getOrderItemId())
                .eqIfPresent(OrderAddrDO::getUserId, reqVO.getUserId())
                .eqIfPresent(OrderAddrDO::getConsignee, reqVO.getConsignee())
                .eqIfPresent(OrderAddrDO::getProvinceId, reqVO.getProvinceId())
                .eqIfPresent(OrderAddrDO::getProvince, reqVO.getProvince())
                .eqIfPresent(OrderAddrDO::getCityId, reqVO.getCityId())
                .eqIfPresent(OrderAddrDO::getCity, reqVO.getCity())
                .eqIfPresent(OrderAddrDO::getAreaId, reqVO.getAreaId())
                .eqIfPresent(OrderAddrDO::getArea, reqVO.getArea())
                .eqIfPresent(OrderAddrDO::getAddrDetail, reqVO.getAddrDetail())
                .eqIfPresent(OrderAddrDO::getPostCode, reqVO.getPostCode())
                .eqIfPresent(OrderAddrDO::getMobile, reqVO.getMobile())
                .eqIfPresent(OrderAddrDO::getLng, reqVO.getLng())
                .eqIfPresent(OrderAddrDO::getLat, reqVO.getLat())
                .betweenIfPresent(OrderAddrDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(OrderAddrDO::getId));
    }

    default Integer deleteByOrderId(BigInteger orderId){
        return delete(new LambdaQueryWrapperX<OrderAddrDO>()
                .eq(OrderAddrDO::getOrderId, orderId)
        );
    }

}
